{% extends "widgets/box.html" %}

{% block box-content %}

<div id="notes_list">
    {% for obj in list %}
        {% include "widgets/notatka.html" %}
    {% endfor %}
</div>

<form action="/widgets/note/add/" method="POST" id="new_note_form" style="padding-top:15px;">
    <div id="new_note_p">
        {{ form.as_p }}
    </div>

    <input type="submit" id="note_nojssubmit"/>

    <p class="buttons" id="send_new_note">
        <span class="button-border"><span class="button" id="send_new_note_b">Zapisz notatkę</span></span>
    </p>
    <p class="buttons" id="show_new_note">
        <span class="button-border"><span class="button">Dodaj notatkę</span></span>
    </p>
    <p class="buttons" id="hide_new_note">
        <span class="button-border"><span class="button">Zrezygnuj</span></span>
    </p>
</form>
<script type="text/javascript">
    $(document).ready(function() {
        $('#new_note_p').hide();
        $('#note_nojssubmit').hide();
        $('#hide_new_note').hide();
        $('#send_new_note').hide();

        $('#show_new_note').click(function() {
            $("#show_new_note").hide();
            $('#new_note_p').slideToggle(250);
            $("#new_note_p").hide();
            $('#hide_new_note').show();
            $('#send_new_note').show();
        });

        function hideForm(){
            $("#id_tresc").val('');
            $("#show_new_note").show();
            $('#new_note_p').slideToggle(250);
            $("#new_note_p").hide();
            $('#hide_new_note').hide();
            $('#send_new_note').hide();
        }

        $('#hide_new_note').click(function() {
            hideForm();
        });

        $("#send_new_note").click(function(){
            dataString = $("#new_note_form").serialize();

            $.ajax({
                type: "POST",
                url: "/widgets/note/add/",
                data: dataString,
                cache: false,

                success: function (html) {
                    if (html) {
                        $('#notes_list').prepend(html);
                    } else {
                        alert('Nie uda\u0142o się zapisać notatki.');
                    }
                }
            });
            hideForm();
        })
    });

</script>

<script type="text/javascript">
    $(function() {
        $(".note_item").editInPlace({
            url: "/widgets/note/edit/",
            bg_over: "#FBEBDC",
            field_type: "textarea",
            value_required : false,
            saving_text: "Zapisywanie...",
            textarea_rows: "4",
            textarea_cols: "38",
            saving_image: "{{ MEDIA_URL }}img/ajax-loader.gif"
        });
    });
</script>

{% endblock %}